package cn.catsdad.page;

import cn.catsdad.base.page.PageParam;
import cn.catsdad.util.StringUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * 用户下拉框查询
 *
 * @author xuyonglong
 * @version V1.0 2023/4/28
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class UserDropdownParam extends PageParam {

    private Collection<Long> departmentIds;
    private Collection<Long> roleIds;
    private Collection<Long> positionIds;
    private Map<String, Object> param = new HashMap<>();

    @Override
    public Map<String, Object> getParamMap() {
        return this.param;
    }

    @Override
    public String getCondition() {
        StringBuilder condition = new StringBuilder(" and u.isDeleted = 0 ");
        if (StringUtil.isNotEmpty(departmentIds)) {
            condition.append(" and u.id in (select du.userId from DtoDepartmentUser du where du.departmentId in :departmentIds)");
            this.param.put("departmentIds", this.departmentIds);
        }
        if (StringUtil.isNotEmpty(roleIds)) {
            condition.append(" and u.id in (select ru.userId from DtoRoleUser ru where ru.roleId in :roleIds)");
            this.param.put("roleIds", this.roleIds);
        }
        if (StringUtil.isNotEmpty(positionIds)) {
            condition.append(" and u.id in (select pu.userUd from DtoPositionUser pu where pu.positionId in :positionIds)");
            this.param.put("positionIds", this.positionIds);
        }
        return condition.toString();
    }
}
